<template>
    <div>
        <Row style="margin:5px 0px 5px 5px">
            <i-col span="1" >
                <Button  size="default"  type="primary" @click="btn_refresh">刷新</Button>
            </i-col>
        </Row>
        <i-table size="default"   border stripe  :columns="format" :data="show_list" :height="sharedState.tableHeight" >
        </i-table >
        <div style="text-align: center;margin-top: 10px;">
            <Page ref="page" :total="total" :page-size="pageSize"  @on-change="changePage" @on-page-size-change="changePageSize" show-total show-sizer/>
        </div>
    </div>
</template>
<script>

import { get_log_list } from  '@/api'
import { post } from '@/api/http'
import { formatUtcTime } from '@/common/util' 
import store from '@/store'

export default {
    data() {
        return {
            sharedState: store.state,
            format: [
                {
                    title: '序列号',key: 'id'
                },
                {
                    title: '任务Id',key: 'task_id'
                },
                {
                    title: '任务名称',key: 'task_name'
                },
                {
                    title: '日志内容',key: 'content'
                },
                {
                    title: '创建时间',key: 'create_time',
                    render:(h,params) => {
                        let value = params.row.create_time
                        let toLocal = formatUtcTime(value)
                        return h('span',toLocal)
                    }
                },
            ],
            // 分页
            total_list: [],
            show_list: [],
            total: 0,
            page: 1,
            pageSize: 20,
        }
    },
    methods: {
		btn_refresh(){
            this.refresh()
        },
        changePage(page) {
            this.page=page
            this.refresh()
        },
        // 每页条数变更
        changePageSize(pageSize){
            this.pageSize = pageSize
            this.refresh()
        },
        refresh() {
            let data = {
                "pageSize":this.pageSize,
                "page":this.page,
            }
            post(get_log_list,data).then(response =>{
                let data = response.data
                this.total  = data.total
                this.show_list = data.data
            })
        }
    },
    mounted: function() {
        setTimeout(() =>{
            this.refresh();
        },200); 
    }
}
</script>
<style>
    pre{
        white-space: pre-wrap!important;
        word-wrap: break-word!important;
        *white-space:normal!important;
    }
</style>